package hot_100;

public class 在排序数组中查找元素的第一个和最后一个位置 {
    public static void main(String[] args) {

    }

    public int[] searchRange(int[] nums, int target) {
        int LL = -1, RR = -1;
        int l = 0, r = nums.length;
        while (r > l) {
            int mid = (r + l) >> 1;
            if (nums[mid] == target) {
                RR = mid;
                r = mid - 1;
            } else if (nums[mid] > target) {
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        l = 0;
        r = nums.length;
        while (r > l) {
            int mid = (r + l) >> 1;
            if (nums[mid] == target) {
                LL = mid;
                l = mid + 1;
            } else if (nums[mid] > target) {
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        return new int[]{LL, RR};
    }
}
